package com.ninetaildemonfox.zdl.socialproject.mvp.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.ninetaildemonfox.zdl.socialproject.base.BaseActivity;
import com.ninetaildemonfox.zdl.socialproject.R;
import com.ninetaildemonfox.zdl.socialproject.mvp.contract.BindingInvitationContract;
import com.ninetaildemonfox.zdl.socialproject.mvp.presenter.BindingInvitationPresenter;

import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author NineTailDemonFox
 * @date 2019/7/24 13:09
 * 功能描述： 绑定邀请码
 * 联系方式：1037438704@qq.com
 */
public class BindingInvitationCodeActivity extends BaseActivity implements BindingInvitationContract {

    @BindView(R.id.image_left_finish)
    ImageView imageleftFinish;
    @BindView(R.id.text_center)
    TextView textCenter;
    @BindView(R.id.text_right)
    TextView textRight;
    @BindView(R.id.text_binding_code)
    TextView textBindingCode;
    @BindView(R.id.edit_code)
    EditText editCode;
    private BindingInvitationPresenter presenter;

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_binding_invitation_code;
    }

    @Override
    protected void onInitialization(Bundle bundle) {
        imageleftFinish.setVisibility(View.VISIBLE);
        textCenter.setText("绑定邀请码");
        presenter = new BindingInvitationPresenter(this, me, this);
        presenter.getWhoInviteMe(token, "", 1);
    }

    @OnClick({R.id.image_left_finish, R.id.text_binding_code})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.image_left_finish:
                finish();
                break;
            case R.id.text_binding_code:
                if (textBindingCode.getText().toString().equals("已绑定邀请码")) {
                    return;
                }
                presenter.getWhoInviteMe(token, editCode.getText().toString().trim(), 2);
                break;
            default:
        }
    }

    @Override
    public void success(Map<String, String> map) {
        editCode.setText(map.get("invite_code"));
        editCode.setFocusable(false);
        editCode.setFocusableInTouchMode(false);
        if (map.get("invite_code") != null) {
            textBindingCode.setText("已绑定邀请码");
            textBindingCode.setBackgroundResource(R.color.tipTextColor);
            textBindingCode.setTextColor(me.getResources().getColor(R.color.white));
        }
    }
}
